deferred class CD_PRIMITIVES_MARKS
--	A mark is a punctual representation. It can have different sizes and types. 
--	All types are affected only by mark attributes and by the foreground color.
--
-- All marks in all drivers are simulated using other CD primitives, except 
-- CanvasPixel.	

inherit
	CANVAS_DRAW

feature {ANY}

	-- Pixel

	draws_pixel (x, y, red, green, blue: INTEGER)
		-- Configures the pixel (x,y) with the color defined. It is the smallest 
		-- element of the canvas. It depends only on global attributes of the 
		-- canvas. It can be very slow on some drivers. Sometimes it is 
		-- implemented as a rectangle with size 1x1.
		local
			cl: INTEGER
		do
			cl := encode_color (red, green, blue)

			int_canvas_pixel (cnvs, x, y, cl)
		end

	draws_pixel_real (x, y: REAL_64; red, green, blue: INTEGER)
		-- As "canvas_pixel" but with REAL_64 for coordinates.
		local
			cl: INTEGER
		do
			cl := encode_color (red, green, blue)

			int_canvas_c_double_pixel (cnvs, x, y, cl)
		end

	wd_draws_pixel (x, y: REAL_64; red, green, blue: INTEGER)
		-- As "canvas_pixel_real" but use World coordinates.
		local
			cl: INTEGER
		do
			cl := encode_color (red, green, blue)

			int_wd_canvas_pixel (cnvs, x, y, cl)
		end

	-- Mark operations

	draws_mark (x, y: INTEGER)
		-- Draws a mark in (x,y) using the current foreground color. It is not 
		-- possible to use this function between a call to functions "begin" and 
		-- "end" if the type of mark is set to diamond. If the active driver does 
		-- not include this primitive, it will be simulated using other 
		-- primitives from the library.
		--
		-- If you will call this function several times in a sequence, then it is 
		-- recommended that the application changes the filling and line 
		-- attributes to those used by this function:
		--
		-- set_interior_style_solid
		-- set_line_style_continuous
		-- set_line_width(1)
		--
		-- This will greatly increase this function's performance. Also in this 
		-- case, if the mark is very small, we suggest using the "canvas_pixel" 
		-- function so that the application itself draws the mark. In many cases, 
		-- this also increases this function's performance.
		do
			int_canvas_mark (cnvs, x, y)
      end

	draws_mark_real (x, y: REAL_64)
		-- As "canvas_mark" but with REAL_64 for coordinates.
		do
			int_canvas_c_double_mark (cnvs, x, y)
      end

	wd_draws_mark (x, y: REAL_64)
		-- As "canvas_mark_real" but use World coordinates.
		do
			int_wd_canvas_mark (cnvs, x, y)
      end

	-- Mark size

	set_mark_size (size: INTEGER)
		-- Configures the mark size in pixels.
		-- Default value: 10.
		require
			size >= 1
		local
			i: INTEGER
		do
			i := int_canvas_mark_size (cnvs, size)
		end

	set_wd_mark_size (size: REAL_64)
		-- Set the current size in millimeters.
		require
			size >= 1
		local
			i: REAL_64
		do
			i := int_wd_canvas_mark_size (cnvs, size)
		end

	get_mark_size: INTEGER
		-- Return the size in pixels.
		do
			Result := int_canvas_mark_size (cnvs, -1)
		end

	get_wd_mark_size: REAL_64
		-- Return the size in millimeters.
		do
			Result := int_wd_canvas_mark_size (cnvs, -1)
		end

	-- Mark attributes

	mark_type_plus: STRING
		local
			i: INTEGER
		do
			i := int_canvas_mark_type (cnvs, 0)
			Result := int_mark_type_integer_to_string(i)
		end

	mark_type_star: STRING
		local
			i: INTEGER
		do
			i := int_canvas_mark_type (cnvs, 1)
			Result := int_mark_type_integer_to_string(i)
		end

	mark_type_circle: STRING
		local
			i: INTEGER
		do
			i := int_canvas_mark_type (cnvs, 2)
			Result := int_mark_type_integer_to_string(i)
		end

	mark_type_x: STRING
		local
			i: INTEGER
		do
			i := int_canvas_mark_type (cnvs, 3)
			Result := int_mark_type_integer_to_string(i)
		end

	mark_type_box: STRING
		local
			i: INTEGER
		do
			i := int_canvas_mark_type (cnvs, 4)
			Result := int_mark_type_integer_to_string(i)
		end

	mark_type_diamond: STRING
		local
			i: INTEGER
		do
			i := int_canvas_mark_type (cnvs, 5)
			Result := int_mark_type_integer_to_string(i)
		end

	mark_type_hollow_circle: STRING
		local
			i: INTEGER
		do
			i := int_canvas_mark_type (cnvs, 6)
			Result := int_mark_type_integer_to_string(i)
		end

	mark_type_hollow_box: STRING
		local
			i: INTEGER
		do
			i := int_canvas_mark_type (cnvs, 7)
			Result := int_mark_type_integer_to_string(i)
		end

	mark_type_hollow_diamond: STRING
		local
			i: INTEGER
		do
			i := int_canvas_mark_type (cnvs, 8)
			Result := int_mark_type_integer_to_string(i)
		end

	mark_type: STRING
		-- Return the type of the mark. One of the follwing string:
		--
	   -- "CD_PLUS"
		-- "CD_STAR"
		--  "CD_CIRCLE"
		-- "CD_X"
		-- "CD_BOX"
		-- "CD_DIAMOND"
		-- "CD_HOLLOW_CIRCLE"
		-- "CD_HOLLOW_BOX"
		-- "CD_HOLLOW_DIAMOND"
		local
			i: INTEGER
		do
			i := int_canvas_mark_type (cnvs, -1)
			Result := int_mark_type_integer_to_string(i)
		end
	

feature {NONE}

	-- Internals

	int_canvas_pixel (wgt: POINTER; x, y, cl: INTEGER)
		external
			"C inline use %"eiffel-iup.h%""
      alias
			"cdCanvasPixel ($wgt, $x, $y, $cl);"
      end

	int_canvas_c_double_pixel (wgt: POINTER; x, y: REAL_64; cl: INTEGER)
		external
			"C inline use %"eiffel-iup.h%""
      alias
			"cdfCanvasPixel ($wgt, $x, $y, $cl);"
      end

	int_wd_canvas_pixel (wgt: POINTER; x, y: REAL_64; cl: INTEGER)
		external
			"C inline use %"eiffel-iup.h%""
      alias
			"wdCanvasPixel ($wgt, $x, $y, $cl);"
      end

	int_canvas_mark (wgt: POINTER; x, y: INTEGER)
		external
			"C inline use %"eiffel-iup.h%""
      alias
			"cdCanvasMark ($wgt, $x, $y);"
      end

	int_canvas_c_double_mark (wgt: POINTER; x, y: REAL_64)
		external
			"C inline use %"eiffel-iup.h%""
      alias
			"cdfCanvasMark ($wgt, $x, $y);"
      end

	int_wd_canvas_mark (wgt: POINTER; x, y: REAL_64)
		external
			"C inline use %"eiffel-iup.h%""
      alias
			"wdCanvasMark ($wgt, $x, $y);"
      end

	int_canvas_mark_size (wgt: POINTER; s: INTEGER): INTEGER
		external
			"C inline use %"eiffel-iup.h%""
      alias
			"return cdCanvasMarkSize ($wgt, $s);"
      end

	int_wd_canvas_mark_size (wgt: POINTER; s: REAL_64): REAL_64
		external
			"C inline use %"eiffel-iup.h%""
      alias
			"return wdCanvasMarkSize ($wgt, $s);"
      end

	int_canvas_mark_type (wgt: POINTER; type: INTEGER): INTEGER
		external
			"C inline use %"eiffel-iup.h%""
      alias
			"return cdCanvasMarkType ($wgt, $type);"
      end

	int_mark_type_integer_to_string (t: INTEGER): STRING
		do
			if t.is_equal(0) then
				Result := "CD_PLUS"
			elseif t.is_equal(1) then
				Result := "CD_STAR"
			elseif t.is_equal(2) then
				Result := "CD_CIRCLE"
			elseif t.is_equal(3) then
				Result := "CD_X"
			elseif t.is_equal(4) then
				Result := "CD_BOX"
			elseif t.is_equal(5) then
				Result := "CD_DIAMOND"
			elseif t.is_equal(6) then
				Result := "CD_HOLLOW_CIRCLE"
			elseif t.is_equal(7) then
				Result := "CD_HOLLOW_BOX"
			elseif t.is_equal(8) then
				Result := "CD_HOLLOW_DIAMOND"
			else
				Result := "CD_PLUS"
			end
		end

end

-- The MIT License (MIT)

-- Copyright (c) 2016, 2019 by German A. Arias

-- Permission is hereby granted, free of charge, to any person obtaining a copy
-- of this software and associated documentation files (the "Software"), to deal
-- in the Software without restriction, including without limitation the rights
-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-- copies of the Software, and to permit persons to whom the Software is
-- furnished to do so, subject to the following conditions:
--
-- The above copyright notice and this permission notice shall be included in 
-- all copies or substantial portions of the Software.
--
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-- SOFTWARE.
